home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Memory / DIMM Config&Interleave v1.1 / FindHammerHead.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-13  |  3.4 KB  |  105 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        FindHammerHead.c
  3.  
  4.     Contains:    A snippet that shows how to find the address of the HammerHead chip.
  5.  
  6.     Written by:    Quinn "The Eskimo!"
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     You may incorporate this sample code into your applications without
  11.     restriction, though the sample code has been provided "AS IS" and the
  12.     responsibility for its operation is 100% yours.  However, what you are
  13.     not permitted to do is to redistribute the source as "DSC Sample Code"
  14.     after having made changes. If you're going to re-distribute the source,
  15.     we require that you make it clear in the source that the code was
  16.     descended from Apple Sample Code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.         
  20.  
  21.     *** need to support the 'fatman' selector too.   
  22. */
  23.  
  24. #include <Types.h>
  25. #include <Errors.h>
  26. #include <CodeFragments.h>
  27. #include <NameRegistry.h>
  28.  
  29. #include "Interleave.h"
  30.  
  31.  
  32. OSStatus FindHammerHead(void* hammerHeadAddress)
  33.     // Sets hammerHeadAddress to the address of the HammerHead
  34.     //  memory controller chip.  This routine looks up the
  35.     //  HammerHead in the Name Registry, then gets the "reg"
  36.     //  property which contains the actual address.  If this
  37.     //  was successful, it returns noErr.  If not, it returns
  38.     //  some (hopefully) appropriate error code.
  39.     // The function guards against the absence of NameRegistryLib,
  40.     //  so you can run this function on any PPC computer.
  41. {
  42.     OSStatus                 err;
  43.     RegEntryIter             myIterator;
  44.     Boolean                 done;
  45.     RegEntryID                 foundEntry;
  46.     RegPropertyValueSize    regPropSize;
  47.     
  48.     // Assume the worst.
  49.     err = unimpErr;
  50.  
  51.     // Check that the link to NameRegistryLib was successfull.
  52.     //  If the address of the RegistryEntryIterateCreate routine
  53.     //  is nil, then the weak link to NameRegistryLib failed,
  54.     //  so we know a) there's no Name Registry for us to call, and
  55.     //  b) the machine doesn't have a HammerHead.
  56.     
  57.     if ( (long) RegistryEntryIterateCreate != kUnresolvedCFragSymbolAddress) {
  58.  
  59.         // Create an iterator.  By default, the iterator is set
  60.         //  to iterate starting at the root of the Name Registry.
  61.         //  This means our subsequent RegistryEntrySearch will
  62.         //  search the entire Name Registry.
  63.         
  64.         err = RegistryEntryIterateCreate(&myIterator);
  65.         if (err == noErr) {
  66.             
  67.             // Create an 'empty' RegEntryID that RegistryEntrySearch
  68.             //  will fill out.
  69.             
  70.             (void) RegistryEntryIDInit(&foundEntry);
  71.  
  72.             // Search for a node in the registry whose "name" property
  73.             //  is "hammerhead".  This will find the first node called
  74.             //  "hammerhead" in the registry.  This routine implicitly
  75.             //  assumes that there is only one HammerHead in the Name
  76.             //  Registry.
  77.             
  78.             err = RegistryEntrySearch(&myIterator, kRegIterContinue, &foundEntry, &done,
  79.                                                         "name", "hammerhead", sizeof("hammerhead"));
  80.  
  81.             if (err == noErr && !done) {
  82.  
  83.                 // We found an entry called "hammerhead".  Get it's
  84.                 //  "reg" property into the UInt32 supplied by the caller.
  85.                 //  Then dispose of the found entry ID.
  86.                                 
  87.                 regPropSize = sizeof(UInt32);
  88.                 err = RegistryPropertyGet(&foundEntry, "reg", hammerHeadAddress, ®PropSize);
  89.                 (void) RegistryEntryIDDispose(&foundEntry);
  90.                 
  91.             } else if (err == noErr) {
  92.                 // We didn't find one, but we're about to return
  93.                 //  noErr, so instead return an appropriate error
  94.                 //  code.
  95.                 err = nrNotFoundErr;
  96.             }
  97.             
  98.             // Dispose of the iterator.
  99.             (void) RegistryEntryIterateDispose(&myIterator);
  100.         }
  101.     }
  102.     
  103.     return (err);
  104. }
  105.